package com.jnshu.controller;

import com.github.pagehelper.Page;
import com.jnshu.constant.Constant;
import com.jnshu.dto.admin.ModelDto;
import com.jnshu.service.ModelService;
import com.jnshu.tools.HeadUtil;
import com.jnshu.tools.binding.JsonUtil;
import com.jnshu.tools.resultUtils.PageBean;
import com.jnshu.tools.resultUtils.ResultBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
public class ModelCon {

    @Resource
    ModelService modelService;

    @GetMapping(value = "/model/list")
    public PageBean getModelList( @RequestParam(name = "pageSize",defaultValue = "10")int pageSize,
                                  @RequestParam(name = "pageNum",defaultValue = "1")int pageNum){
        log.info ("_____________________________________________");
        log.info("方法manageList接收到的请求参数为："+pageNum+","+pageSize);
        return modelService.selectModelList(pageNum,pageSize);
    }

    @DeleteMapping(value = "/model/{id}")
    public ResultBean deleteModel(@PathVariable("id")long id){
        log.info ("_____________________________________________");
        log.info("方法manageList接收到的请求参数为："+id);
        return modelService.deleteByPrimaryKey(id);
    }

    @PutMapping(value = "/model/",produces = {"application/json;charset=UTF-8"})
    public ResultBean updateModel(@RequestBody ModelDto modelDto){
        log.info ("_____________________________________________");
        log.info("方法manageList接收到的请求参数为："+ JsonUtil.toJsonString(modelDto));
        return modelService.updateByPrimaryKeySelective(modelDto, HeadUtil.getHeadValue(Constant.LOGINID));
    }

    @PostMapping(value = "/model",produces = {"application/json;charset=UTF-8"})
    public ResultBean insertModel(@RequestBody ModelDto modelDto){
        log.info ("_____________________________________________");
        log.info("方法manageList接收到的请求参数为："+JsonUtil.toJsonString(modelDto));
        return modelService.insertSelective(modelDto, HeadUtil.getHeadValue(Constant.LOGINID));
    }
}
